package com.itheima.d3_collection_list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListTest2 {
    public static void main(String[] args) {

        //list
        List<String > list =new ArrayList<>();
        list.add("孙悟空");
        list.add("猪八戒");
        list.add("齐天大圣");
        list.add("沙悟净");

        for (int i = 0; i < list.size(); i++) {
            String s1 =list.get(i);
            System.out.println(s1);
        }

        Iterator<String> iterator = list.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }

        for(String s2:list){
            System.out.println(s2);
        }

        list.forEach(System.out::println);
    }
}
